<?php
class UserTable extends Zend_Db_Table {
	
	protected function _setup() {
		$this->_name = DB_PRE . 'user';
		$this->_primary = 'id';
		parent::_setup ();
	}
	
	public function insert($data) {
		if (empty ( $data ['time'] )) {
			$data ['time'] = time ();
		}
		return parent::insert ( $data );
	}
	
	public function checkUser($name) {
		global $db;
		$where = $db->quoteInto ( "`username` = ?", $name );
		return $this->fetchAll ( $where )->count ();
	}
	
	public function checkEmail($email) {
		global $db;
		$where = $db->quoteInto ( "`email` = ?", email );
		return $this->fetchAll ( $where )->count ();
	}
	
	public function fetchByEmail($email) {
		global $db;
		$where = $db->quoteInto ( "`email` = ?", $email );
		return $this->fetchAll ( $where );
	}
	
	public function validate($id, $validate) {
		global $db;
		$where = $db->quoteInto ( "`id` = ?", $id );
		$where .= $db->quoteInto ( " AND `validate` = ?", $validate );
		return $this->fetchAll ( $where );
	}
	
	public function login($user, $password) {
		global $db;
		$where = $db->quoteInto ( "`username` = ?", $user );
		$where .= $db->quoteInto ( " AND `password` = ?", $password );
		return $this->fetchAll ( $where );
	}

}

?>